<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <%layout("/WEB-INF/view/common/inc/admin_head.html",{title:'', styles:'bootstrap,font-awesome,animate,style,bootstrap-table,layui-date,auto-complete,dtvalidate,layui,chosen,fancybox'}){%>
    <style type="text/css">
        body{padding-top:10px;
            padding-left: 10px;}
        *{margin:0;padding:0;list-style-type:none;}
        a,img{border:0;}
        .demo h2{font-size:16px;color:#3366cc;height:30px;}
        .demo li{float:left;}
    </style>
    <%}%>
</head>

<body>
<div class="row">
    <div class="col-sm-12">
        <!-- START 右侧数据 -->
        <div class="ibox float-e-margins" style="margin-bottom: 0px;">
            <div class="ibox-content" style="padding:15px 20px 0px 20px;">
                <form id="search-form" role="form" class="form-horizontal" autocomplete="off">
                    <input type="hidden" readonly id="productMember" name="productMember"  class="form-control" value="${user.userRealname}">
                    <div class="form-group">
                        <label class="control-label col-sm-1">供应商:</label>
                        <div class="col-sm-2">
                            <input type="text" id="supplierName" name="supplierName" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">柜号:</label>
                        <div class="col-sm-2">
                            <input type="text" id="createPlanNo" name="createPlanNo" class="form-control">
                        </div>
                        <label class="control-label col-sm-1">状态:</label>
                        <div class="col-sm-2">
                            <select id="billStatus" name="billStatus" class="form-control">
                                <option value="">全部分类</option>
                                <option value="0" >待审核</option>
                                <option value="1" >审核中</option>
                                <option value="2" >审核通过</option>
                                <option value="3" >已拒绝</option>
                            </select>
                        </div>

                        <a class="search-btn btn btn-success" style="margin-bottom: 0px;">查询</a>
                    </div>
                </form>
            </div>
            <!-- START 操作按钮 -->
            <form>
                <div id="toolbar" class="btn-group" style="margin-bottom:5px;">
                    <button  class="add-btn layui-btn layui-btn-normal layui-btn-sm" >
                        <i class="fa fa-plus" aria-hidden="true"></i> 新增发票
                    </button>
                </div>
            </form>
            <!-- END 操作按钮 -->

            <!-- START 数据表格 -->
            <table id="relatedTable"
                   data-toolbar="#toolbar"
                   data-side-pagination="server"
                   data-pagination="true"
                   data-resizable="true"
                   data-url="/sea/supply/bill/findByCnd.do"
                   data-page-size="15"
                   class="table table-striped table-hover"
            >
            </table>
            <!-- END 数据表格 -->
        </div>
    </div>
</div>
<%layout("/WEB-INF/view/common/inc/admin_js.html",{modules:'jquery,bootstrap,bootstrap-table,bootstrap-table-zh-CN,dtvalidate,dtvalidate-lang-zh_cn,laydate,layer,layui,chosen,chosen-demo,upload,imgbox'}){}%>
<script>


    var $relatedTable = $('#relatedTable');
    $(function(){
        $('.fancybox').fancybox({
            openEffect: 'none',
            closeEffect: 'none'
        });
        //START 表格配置
        $relatedTable.bootstrapTable({
            columns: [
                {
                    title: '供应商',
                    field: 'supplierName',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '柜号',
                    field: 'createPlanNo',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '不含税金额',
                    field: 'billPrice',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '税额',
                    field: 'billTax',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '含税金额',
                    field: 'billMoney',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '发票号码',
                    field: 'billNumber',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '发票代码',
                    field: 'billCode',
                    align: 'center',
                    valign: 'middle'
                },
                {
                    title: '发票图片',
                    field: 'billImg',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        if(null!=v && v!=''){
                            return '<a class="fancybox" href="'+v+'"><img src="' + v + '" style="width:80px;height:60px;"/></a>';;
                        }else{
                            return '';
                        }
                    }
                },
                {
                    title: '状态',
                    field: 'billStatus',
                    align: 'center',
                    valign: 'middle',
                    formatter:function (v,r) {
                        var result='';
                        switch (v) {
                            case 0:
                                result='待审核';
                                break;
                            case 1:
                                result='审核中';
                                break;
                            case 3:
                                result='已拒绝';
                                break;
                            case 2:
                                result='审核通过';
                                break;

                            default:
                                result='';
                        }
                        return result;
                    }
                },
                {
                    field: 'operate',
                    title: '操作',
                    align: 'center',
                    valign: 'middle',
                    formatter: optFormatter
                }
            ],
            onLoadSuccess : function(){
                //修改按钮
                $('.edit-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.open({
                        title: false,
                        closeBtn: 0,
                        type: 2,
                        area: ['100%','100%'],
                        skin: 'layer-ext-espresso',
                        content: ['/sea/supply/bill/editPage.do?id='+id, 'yes']
                    });
                });
                $('.del-btn').on('click',function(){
                    var id = $(this).attr('data-val');
                    layer.confirm('确定要删除当前？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        $.post('/sea/supply/bill/delete.do',{id: id},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $relatedTable.bootstrapTable('refresh');
                                });
                            }else{
                                layer.msg(data.msg,{icon: 0,time: 1500});
                            }
                        });
                    });
                });
                $('.btn-send').on('click',function(){
                    var id = $(this).attr('data-val')
                    layer.confirm('确定要推送当前数据？', {
                        btn: ['确定','取消'],title:'提示'
                    }, function(){
                        layer.closeAll();
                        layer.load();
                        $.post('/sea/supply/bill/usave.do',{id: id,billStatus:1,flag:1},function(data){
                            if( data.ok ){
                                layer.msg(data.msg,{icon: 1,time: 1500},function(){
                                    //刷新页面
                                    $relatedTable.bootstrapTable('refresh');
                                    layer.closeAll();
                                });
                            }else{
                                layer.closeAll(); //关闭弹窗
                                layer.msg(data.msg,{icon: 0,btn: ['确定'],time:0,shade: [0.8, '#393D49'],yes: function(index, layero){
                                        layer.closeAll();
                                    }});
                            }
                        });
                    });
                });
            }
        });
        //新增
        $('.add-btn').on('click',function(){//新增
            layer.open({
                title: false,
                closeBtn: 0,
                type: 2,
                area: ['100%','100%'],
                skin: 'layer-ext-espresso',
                content: ['/sea/supply/bill/addPage.do', 'yes']
            });
        });
        $('.search-btn').on('click',function(){
            $relatedTable.bootstrapTable('refresh', { url:'${ctxPath}/sea/supply/bill/findByCnd?'+$('#search-form').serialize() });
        });

        //操作菜单
        function optFormatter(value,row){
            var content= '';
            if(row.billStatus==0) {
                content += '<button class="btn-send btn btn-xs btn-success" data-val="' + row.id + '" title="推送">  推送至财务</button>';
                content += '&nbsp;<button class="edit-btn btn btn-xs btn-info" data-val="' + row.id + '" title="修改"><i class="fa fa-edit"></i>  </button>';
                content += '<button class="del-btn btn btn-xs btn-danger" data-val="' + row.id + '" title="删除" style="margin-left: 5px;"><i class="fa fa-trash"></i>  </button>';
            }
            return content;
        }
    });

</script>
</body>
</html>
